package com.buildings.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.buildings.R;
import com.bumptech.glide.Glide;

import java.util.Collections;
import java.util.List;

public class ImgsAdapter extends BaseAdapter {

    private Context context;
    /**
     * 图片文件绝对路径
     */
    private List<String> data;
    // 强引用bitmap集合可能引起OOM
//	public Bitmap bitmaps[];
//    private OnItemClickClass onItemClickClass;

    public ImgsAdapter(Context context, List<String> data
    ) {
        this.context = context;
        this.data = data;
        // 倒叙
        Collections.reverse(this.data);
//        this.onItemClickClass = onItemClickClass;
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int arg0) {
        return data.get(arg0);
    }


    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.commactivity_imgsitem, null);
            holder = new Holder();
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);
            holder.checkBox = (ImageView) convertView.findViewById(R.id.checkBox1);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }

        // UIL框架加载本地图片
        Glide.with(context).load(data.get(position))
                .into(holder.imageView);
//        convertView.setOnClickListener(new OnPhotoClick(position, holder.checkBox));
        return convertView;
    }

    class Holder {
        ImageView imageView;
        ImageView checkBox;
    }

//    public interface OnItemClickClass {
//        public void OnItemClick(View v, int Position, ImageView checkBox);
//    }

//    class OnPhotoClick implements OnClickListener {
//        int position;
//        ImageView checkBox;
//
//        public OnPhotoClick(int position, ImageView checkBox) {
//            this.position = position;
//            this.checkBox = checkBox;
//        }
//
//        @Override
//        public void onClick(View v) {
//            if (data != null && onItemClickClass != null) {
//                onItemClickClass.OnItemClick(v, position, checkBox);
//            }
//        }
//    }

}
